home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bincon10.zip / BINCON.C < prev    next >
C/C++ Source or Header  |  1993-02-12  |  5KB  |  150 lines

  1. /*   ╔══════════════════════════════════════════════════════════════╗
  2.      ║        All of the files included in this BINCON package      ║
  3.      ║  are (C)opyright 1993 Tim Triemstra, All Rights are Reserved ║
  4.      ║                                                              ║
  5.      ║  The author can be contacted at:                             ║
  6.      ║  Internet: empath@ais.org                                    ║
  7.      ║  UUCP:     umcc!roofus!empath                                ║
  8.      ║  Fido:     Tim Triemstra @ 1:2410/339.1                      ║
  9.      ╚══════════════════════════════════════════════════════════════╝ */
  10.  
  11. /*
  12.     This file is probably pretty ugly to alot of you "professional
  13.     programmers" (or anybody else actuall.)  However, since I am
  14.     just a guy who learned myself all mines knowledge on mines own =)
  15.     - don't expect too much.
  16.  
  17.     I included the source because there is probably a situation
  18.     that someone out there mich like some more functionality.  I can't
  19.     really think of anything off the top of my head (after all, I
  20.     wrote this program for myself anyhow.)
  21.  
  22.     Please, if this code influences you to write an application along
  23.     this line, release it as shareware/freeware.  The world needs
  24.     good programs and if we all have to spend our precious minutes
  25.     writing small tools like this then the real programs will take
  26.     alot longer.
  27.  
  28.     I'm constantly writing small programs like this myself and I try
  29.     to release them all into the public domain with source code.  The
  30.     only thing I ask is that if you use it constantly - distribute it!
  31.     After all, you're not the only wierd one out there that may like
  32.     this program.
  33.  
  34.     Finally, I doubt I'll do too much more with this program, but in
  35.     the interest of keeping the good stuff rolling, I do accept
  36.     donations.  I'll be sure to send you back some mail with some little
  37.     tidbit of code or info that you may find interesting.  Sometimes
  38.     it'll be an update, other times I'll send you other code that I may
  39.     be working on that you may be interested in.  If you have a specific
  40.     application you may want some help with, or are looking for little
  41.     tidbits, let me know.  I may have some code lying around...  And,
  42.     ESPECIALLY, if you have an internet mail site (or Fido I guess)
  43.     let me know it and I can get you alot more stuff sent to you.
  44.  
  45.     I'd ask for something like $7 for a general, all purpose donation.
  46.     If you'd like some graphics coding information (my real speciality)
  47.     I'll gladly send you a disk full of stuff for a little more money.
  48.     I prefer to handle most of this stuff via regular mail or, especially,
  49.     internet mail.  So, here's the info:
  50.  
  51.     Send any donations (along with your personal info so I can keep in
  52.     touch and send you some stuff you might like, and keep track of
  53.     my fellow programmers) to:
  54.  
  55.     Tim Triemstra
  56.     Empath Software
  57.     6238 College Drive
  58.     Dearborn Heights, MI 48127
  59.  
  60.     * Make any checks/money orders payable to Tim Triemstra, my bank is
  61.       still trying to charge me for depositing company checks so I don't
  62.       deal with them like that yet.
  63.  
  64.     I can be contacted at:
  65.     Internet:  empath@ais.org
  66.     Fidomail:  Tim Triemstra @ 1:2410/339.1 (I'm a point so I see it all)
  67.     UUCPmail:  umcc!roofus!empath
  68.  
  69.     This info is also included in the readme.txt, but I know I love to
  70.     delete those darn files so I put it here as well.  There IS some
  71.     other good info in the readme though too...
  72. */
  73.  
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. #include <dos.h>
  77.  
  78. void main(int argc, char *argv[])
  79. {
  80.     FILE *f;
  81.     unsigned char   *raw;
  82.     unsigned int    length;
  83.     unsigned int    count;
  84.     short           count2;
  85.     int             start, end;
  86.  
  87.     if(argc < 3)
  88.     {
  89. #ifdef DOS386
  90.     puts("32bit usage: BIN2DEC <infile> <type D:H> <start> <end>");
  91.     puts("The <start> defaults to 0, the <end> defaults to the eof\n");
  92. #else
  93.     puts("16bit usage: BIN2DEC <infile> <type D:H> <start> <end>");
  94.     puts("The <start> defaults to 0, the <end> defaults to the eof\n");
  95. #endif
  96.     exit(1);
  97.     }
  98.  
  99.     f = fopen(argv[1],"rb");
  100.     if(!f)
  101.     {
  102.     printf("Could not open the requested file \"%s\"\n",argv[1]);
  103.     goto EXIT;
  104.     }
  105.     length = (int)filelength(fileno(f));
  106.  
  107. #ifdef DOS386
  108.     raw = (unsigned char*)malloc(length*sizeof(char));
  109. #else
  110.     raw = farmalloc(length*sizeof(char));
  111. #endif
  112.     fread(raw,1,length,f);
  113.     fclose(f);
  114.  
  115.     start = 0; end = length;
  116.     if(argc > 3)
  117.         start = atoi(argv[3]);
  118.     if(argc > 4)
  119.         end = atoi(argv[4]);
  120.  
  121.     count2 = -1;
  122.     printf("\n{\n    ");
  123.     /* This will simply output to the screen, good for >filename work */
  124.     for(count = start; count < end; count++)
  125.     {
  126.         if(count != start)
  127.             printf(",");
  128.  
  129.         ++count2;
  130.         if(count2 > 11)
  131.         {
  132.             count2 = 0;
  133.             printf("\n    ");
  134.         }
  135.         switch(argv[2][0])
  136.         {
  137.             case 'd' :   printf(" %3d",raw[count]); break;
  138.             case 'D' :   printf(" %3d",raw[count]); break;
  139.             case 'h' :   printf("%#4x",raw[count]); break;
  140.             case 'H' :   printf("%#4x",raw[count]); break;
  141.             default  : exit(0);
  142.         }
  143.     }
  144.     printf("\n};\n");
  145.  
  146. EXIT:
  147.     printf("\n");
  148.     exit(0);
  149. }
  150.